package com.itheima.controller;


import com.itheima.common.R;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-28
 */
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public R list() {
        List<Dept>list=deptService.list();
        return R.ok(list);
    }
    @PostMapping
    public R save(@RequestBody  Dept dept) {
        deptService.save(dept);
        return R.ok();
    }
    @DeleteMapping()
    public R delete(@RequestParam Integer id) throws FileNotFoundException {
        deptService.delete(id);
        return R.ok();

    }
    @GetMapping("/{id}")
    public R get(@PathVariable("id") Integer id) {
        Dept dept=deptService.getById(id);
        return R.ok(dept);
    }
    @PutMapping
    public R update(@RequestBody Dept dept) {
        deptService.updateById(dept);
        return R.ok();
    }
}
